package com.iuhao.web.config;

import com.google.common.base.Predicate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

import static com.google.common.base.Predicates.or;
import static springfox.documentation.builders.PathSelectors.regex;

/**
 * @author Liu Jianwei<liujianwei@credit.com>
 * @date 2016-3-30
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
            .groupName("cbim-app-api")
            .select()
            .paths(paths())
            .build()
            .apiInfo(apiInfo());
    }

    private Predicate<String> paths() {
        return or(
            regex("/common.*"),
            regex("/order.*"),
            regex("/test.*"));
    }

    private ApiInfo apiInfo() {
        String title = "cbim管理接口";
        String description = "cbim管理接口文档";
        String version = "1.0.0-snapshot";
        Contact DEFAULT_CONTACT = new Contact("", "", "");
        ApiInfo apiInfo = new ApiInfo(title, description, version,
            "", DEFAULT_CONTACT, "", "", new ArrayList());
        return apiInfo;
    }
}
